import { GaRegExp, RuleInfo, ruleInjectable } from "../InjectionRule";

const defaultVarName: string[] = [
	"var",
	"let",
	"bind",
	"const",
	"final",
	"static",
	"type",
	"class",
	"interface",
	"struct",

	"set",
	"get",

	"func",
	"return",

	"public",
	"private",
	"protected",

	"new",
	"default",

	"while",
	"do",
	"loop",
	"for",

	"if",
	"else",

	"try",
	"catch",
	"finally",

	"true",
	"false",

	"as",

];

@ruleInjectable()
export default class variableNameRule extends GaRegExp {

	public RuleInit() {
		this.ParseRule([this.Supply("VAR_NAME"), "(!", "[\\_a-zA-Z\\u4e00-\\u9fa5][\\_a-zA-Z0-9\\u4e00-\\u9fa5]*", this.endHandle, ")"]);
	}

	private endHandle: RuleInfo = {
		ruleType: "position",
		ruleData: (save, origin, rule, str, index, char, length) => {
			if (defaultVarName.includes(GaRegExp.GetLastCatch(origin))) {
				return false;
			}
			return true;
		},
	};

}
